package cn.kgc.springbootdemo.exception;


import cn.kgc.springbootdemo.enums.ResultEnum;
import lombok.Data;
import org.springframework.http.HttpStatus;

/**
 * <h3>springbootdemo</h3>
 * <p>抛出异常</p>
 *
 * @author : DongZeJian
 * @date : 2020-04-28 11:07
 **/
@Data
public class HandleException extends RuntimeException {

    private Integer code;

    //状态
    private HttpStatus httpStatus;

    public HandleException(ResultEnum resultEnum) {
        super(resultEnum.getMessage());
        this.code = resultEnum.getCode();
    }

    public HandleException(Integer code, String message) {
        super(message);
        this.code = code;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }


    public HttpStatus getStatus() {
        return this.httpStatus == null ? HttpStatus.INTERNAL_SERVER_ERROR  : this.httpStatus;
    }

}
